/**********************************************************************\

 Copyright 2012 Diggory Blake

 This file is part of klip-engine

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

\**********************************************************************/
#pragma once

class kResources;
class kStream;

#include "kcommon.h"
#include "kcomponent.h"
#include "kdata.h"

class kResources : public kComponent {
private:
	std::map<std::tstring, kDataBufferView*> _lockedData;
	std::map<kDataBufferView*, std::pair<std::tstring, int> > _lockedResources;

protected:
	virtual kStream* doOpen(const std::tstring& uri) = 0;
	virtual void doClose(kStream* stream) = 0;
	virtual void doUpdate(const std::tstring& uri, kStream* stream);

public:
	kDataBufferView* lock(const std::tstring& uri);
	void unlock(kDataBufferView* data);
	void update(const std::tstring& uri, const kDataView& data);
	kStream* open(const std::tstring& uri);
	void close(kStream*& stream);
	void update(const std::tstring& uri, kStream* stream);
};
